import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Subject } from 'rxjs/Subject';
import { Http, Headers, Response } from '@angular/http';
import { User} from '../model/user-model';
import {GlobalService} from "../../global.service";

@Injectable()
export class UserLoginService {
  public userLoginURL = 'mock-data/user-login-mock.json';
  public subject: Subject<User> = new Subject<User>();

  constructor(public http:Http,
              private globalService:GlobalService,){}

  public get currentUser():Observable<User>{
      return this.subject.asObservable();
  }

  public login(data): Observable<any>{
      return this.http.post(this.globalService.api+"/services/auth/checkLogin",data);
  }

  public logout():void{
    localStorage.removeItem("currentUser");
    location.reload();
  }
}
